package com.lm.service;

import com.lm.dao.UserMapper;
import com.lm.pojo.User;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.List;

/**
 * 方式一：
 * 创建Mapper接口的实现类，并且声明sqlSessionTemplate 通过set注入 注入sqlSessionTemplate
 */
public class UserMapperImpl implements UserMapper {

    private SqlSessionTemplate sqlSessionTemplate;

    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    public List<User> getUserList() {
        return sqlSessionTemplate.getMapper(UserMapper.class).getUserList();
    }

    public int insert(User user) {
        return sqlSessionTemplate.getMapper(UserMapper.class).insert(user);
    }

    public User getUserById(int id) {
        return sqlSessionTemplate.getMapper(UserMapper.class).getUserById(id);
    }

    public int updateUser(User user) {
        return sqlSessionTemplate.getMapper(UserMapper.class).updateUser(user);
    }

    public int deleteUser(int id) {
        return sqlSessionTemplate.getMapper(UserMapper.class).deleteUser(id);
    }

    public User getUserByIdForMap(int id) {
        return sqlSessionTemplate.getMapper(UserMapper.class).getUserByIdForMap(id);
    }
}
